package com.coolwen.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.coolwen.dao.UserMapper;
import com.coolwen.entity.User;
import com.coolwen.util.BeanUtil;
import com.coolwen.util.PagedResult;

/**
 * 功能概要：UserService实现类
 * 
 * @author
 * @since  2015年9月28日 
 */
@Service("userservice")
public class UserServiceImpl implements UserService{
	@Autowired
	private UserMapper userDao;

    @Override
	public User selectByPrimaryKey(Integer userId) {
		return userDao.selectByPrimaryKey(userId);
		
	}




    @Override
	public List<User> selectUserByUserName(String userName) {
		List<User> list = userDao.selectUserByUserName(userName);
		return list;
	}

    @Override
    public int insertSelective(User record) {
        return  userDao.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return userDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int deleteByPrimaryKey(Integer userId) {
        return userDao.deleteByPrimaryKey(userId);
    }

    @Override
    public PagedResult<User> queryByPage(String userName,Integer pageNo,Integer pageSize ) {
		pageNo = pageNo == null?1:pageNo;
		pageSize = pageSize == null?10:pageSize;
		PageHelper.startPage(pageNo,pageSize);  //startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		return BeanUtil.toPagedResult(userDao.selectUserByUserName(userName));
	}

}
